using System;
using System.Collections;
using System.Collections.Generic;
using CinemaDirector;
using UnityEngine;

public class ScoreDialog : MonoBehaviour
{
	public GameObject uiGameObject;

	public GameObject msgUiGameObject;

	public new UILabel name;

	public UISprite flag;

	public UILabel centerLabel;

	public UILabel bottomLabel;

	public UILabel msg1Label;

	public UILabel msg2Label;

	public Cutscene showAnimation;

	public Cutscene delayAnimation;

	public Cutscene hideAnimation;

	public Cutscene msgInAnimation;

	public Cutscene msgOutAnimation;

	protected Action onComplete;

	protected List<Cutscene> cutscenesToShow = new List<Cutscene>();

	protected int currentCutsceneIndex;

	private bool initialized;

	protected void ShowNextCutscene()
	{
		if (currentCutsceneIndex >= cutscenesToShow.Count)
		{
			cutscenesToShow.Clear();
			currentCutsceneIndex = 0;
			uiGameObject.SetActive(false);
			msgUiGameObject.SetActive(false);
			StartCoroutine(DoOnComplete(onComplete));
		}
		else
		{
			cutscenesToShow[currentCutsceneIndex].Play();
			Debug.Log("Showing cutscene " + currentCutsceneIndex);
			currentCutsceneIndex++;
		}
	}

	private void Init()
	{
		if (!initialized)
		{
			uiGameObject.SetActive(false);
			msgUiGameObject.SetActive(false);
			Cutscene[] array = new Cutscene[5] { showAnimation, delayAnimation, hideAnimation, msgInAnimation, msgOutAnimation };
			Cutscene[] array2 = array;
			foreach (Cutscene cutscene in array2)
			{
				cutscene.CutsceneFinished -= CutsceneHandler;
				cutscene.CutsceneFinished += CutsceneHandler;
			}
			initialized = true;
		}
	}

	public void Awake()
	{
		Init();
	}

	public void Show(UIPlayerScoreBoard scoreBoard, string mainText, string subText, float duration = 3f, Action onComplete = null)
	{
		Init();
		uiGameObject.SetActive(true);
		msgUiGameObject.SetActive(false);
		uiGameObject.transform.localScale = Vector3.one;
		flag.spriteName = scoreBoard.flag.spriteName;
		name.text = scoreBoard.name.text;
		centerLabel.text = mainText;
		bottomLabel.text = subText;
		this.onComplete = onComplete;
		currentCutsceneIndex = 0;
		cutscenesToShow.Clear();
		cutscenesToShow.Add(showAnimation);
		delayAnimation.Duration = duration;
		cutscenesToShow.Add(delayAnimation);
		cutscenesToShow.Add(hideAnimation);
		ShowNextCutscene();
	}

	public void ShowMsg(string mainText, string subText, float duration = 0.5f, Action onComplete = null)
	{
		Init();
		uiGameObject.SetActive(false);
		msgUiGameObject.SetActive(true);
		msg1Label.text = mainText;
		msg2Label.text = subText;
		this.onComplete = onComplete;
		currentCutsceneIndex = 0;
		cutscenesToShow.Clear();
		cutscenesToShow.Add(msgInAnimation);
		delayAnimation.Duration = duration;
		cutscenesToShow.Add(delayAnimation);
		cutscenesToShow.Add(msgOutAnimation);
		ShowNextCutscene();
	}

	private void CutsceneHandler(object sender, CutsceneEventArgs e)
	{
		ShowNextCutscene();
	}

	private IEnumerator DoOnComplete(Action onComplete)
	{
		yield return null;
		if (onComplete != null)
		{
			onComplete();
		}
	}
}
